<?php

/**
 * Contact presenter.
 */
class HomePresenter extends BasePresenter
{
    public function renderDefault()
    {
        $this->_renderGallery();
        $this->template->registerHelper('json', 'json_encode');
    }
    
    private function _renderGallery()
    {
        $photos = WDB\Wrapper\TableFactory::fromName('gallery')
                ->datasource
                ->run();
        
        $this->template->photos = array();
        $i = 0;
        foreach ($photos as $photo)
        {
            $p = $photo->array;
            $p['class']=$this->photoCssClass($i, count($photos));
            $this->template->photos[$p['id_photo']] = $p;
            ++$i;
        }
        
        $photo1 = WDB\Utils\Arrays::first($this->template->photos);
        $this->template->firstPhoto = $photo1['id_photo'];
    }
    
    private function photoCssClass($number, $total)
    {
        switch ($number)
        {
            case '0':
                return 'photo';
            case '1':
                return 'photon1';
            case '2':
                return 'photon2';
            case $total-2:
                return 'photop2';
            case $total-1:
                return 'photop1';
            default:
                return 'photoHidden';
        }
    }
}
